//
//  HSYBaseTabBarController.m
//  HSY
//
//  Created by 陈浩 on 2017/4/1.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYBaseTabBarController.h"
#import "HSYBaseTabBar.h"
#import "HSYBaseTabBarItem.h"
#import "HSYBaseNavigationController.h"
#import "HSYBaseNavigationBar.h"

@interface HSYBaseTabBarController ()

@end

@implementation HSYBaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    HSYBaseTabBar *tabbar = [[HSYBaseTabBar alloc] init];
    [self setValue:tabbar forKeyPath:@"tabBar"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)addChildViewController:(HSYBaseViewController *)childViewController image:(UIImage *)image  selectedImage:(UIImage*) selectedImage title:(NSString *)title inNavigationCongroller:(BOOL)inNavigationCongroller{
    //使用自定义的tabBarItem,以便遍历badge身上的view
    HSYBaseTabBarItem *item = [[HSYBaseTabBarItem alloc] init];
    childViewController.tabBarItem = item;
    
    item.tag = self.childViewControllers.count;
    //    item.tipView.hidden = NO;
    
    //设置选中与未选中的图片-->指定一下渲染模式-->图片以原样的方式显示出来
    childViewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childViewController.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置标题
    childViewController.tabBarItem.title = title;

    if (inNavigationCongroller) { //是否需要将试图控制器放入导航控制器中
        HSYBaseNavigationController *nav = [[HSYBaseNavigationController alloc] initWithRootViewController:childViewController];
        HSYBaseNavigationBar *bar = [[HSYBaseNavigationBar alloc] init];
        [nav setValue:bar forKey:@"navigationBar"];
        
        [self addChildViewController:nav];
    }else{
        [self addChildViewController:childViewController];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
